package com.devbobcorn.oddities.client;

import com.devbobcorn.oddities.Oddities;

import net.minecraftforge.fml.common.Mod.EventBusSubscriber;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.ICloudRenderHandler;
import net.minecraftforge.client.event.RenderLevelLastEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;

@EventBusSubscriber(value = Dist.CLIENT, modid=Oddities.MODID, bus=Bus.FORGE)
public class CloudRetainer {
    private static Logger LOGGER = LogManager.getLogger("Cloud Retainer");
    private static Minecraft mc = null;
    private static ICloudRenderHandler cloudRender = new CornCloudRender();

    @SubscribeEvent
    public static void onRenderCloud(RenderLevelLastEvent event) {
        if (mc == null) {
            mc = Minecraft.getInstance();
        } else if (mc.level.effects().getCloudRenderHandler() != cloudRender){
            mc.level.effects().setCloudRenderHandler(cloudRender);
            LOGGER.info("Cloud Renderer Set");
        }
    }
}
